<?php
/**
 *
 * 모델 instance 를 반환하는 추상 클래스
 *
 */

class modelAbstract
{
    public static $instance;

    public static function getModel($className, $sTable, $db)
    {
        $className = self::getClassName($className, $sTable);
        
        if (!class_exists($className)) {
            throw new exceptionDb($sTable.' 에 해당하는 model 이 없습니다.');
        }

        if (!empty(self::$instance[$className])) {
            return self::$instance[$className];
        }
        
        self::$instance[$className] = new $className($db);

        return self::$instance[$className];
    }

    public static function getClassName($className, $sTable)
    {
        $aTable = explode('_', $sTable);
        for ($i = 0; $i < count($aTable); $i++) {
            $className .= ucfirst(strtolower($aTable[$i]));
        }

        return $className;
    }
}